package com.java.gmall.service.impl;

import com.alibaba.dubbo.config.annotation.Reference;
import com.atguigu.gmall.bean.UserAddress;
import com.atguigu.gmall.service.OrderService;
import com.atguigu.gmall.service.UserService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * @author jingjintao
 * @date 2021/8/21 - 23:53
 **/
@Service
public class OrderServiceImpl implements OrderService {

//    @Autowired
//    @Reference(url = "127.0.0.1:20882") //dubbo直连
//    @Reference(loadbalance = "roundrobin") //基于权重的轮训
    @Reference(loadbalance = "random",timeout = 1000) //基于权重的轮训
    UserService userService;

    @HystrixCommand(fallbackMethod = "hello")
    @Override
    public List<UserAddress> initOrder(String userId) {
        //查询用户的收货地址
        System.out.println("用户id："+userId);
        List<UserAddress> userAddressList = userService.getUserAddressList(userId);
        for (UserAddress userAddress : userAddressList) {
            System.out.println(userAddress.getUserAddress());
        }
        return userAddressList;
    }

    public List<UserAddress> hello(String userId) {
        return Arrays.asList(new UserAddress(10,"测试","测试","测试","测试","Y"));
    }
}
